﻿/**
<code>
  <author name="Zealic" email="zealic(at)gmail.com" type="Creator"/>
</code>
**/
using System;


namespace Zealib.Template
{
    public class EnvironmentVariableSource : IVariableSource
    {
        public EnvironmentVariableSource()
            : this(null)
        {
        }

        public EnvironmentVariableSource(EnvironmentVariableTarget? target)
        {
            Target = target;
        }


        public EnvironmentVariableTarget? Target
        {
            get;
            set;
        }

        public virtual string Resolve(string expression)
        {
            if (expression == null) throw new ArgumentNullException("expression");
            if (Target == null)
            {
                return Environment.GetEnvironmentVariable(expression);
            }
            return Environment.GetEnvironmentVariable(expression, Target.Value);
        }
    }
}
